package com.regentsoft.cloudback.exception;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.regentsoft.cloudback.base.BaseResp;
import com.regentsoft.cloudback.base.ResponseCode;

/**
 * 
 * @author czd
 *
 * @date 2017年12月8日
 *
 * @version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {
	private final Logger LOGGER = Logger.getLogger(this.getClass());
	@ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public BaseResp runtimeExceptionHandler(HttpServletRequest req, RuntimeException e){
		LOGGER.error(e.getMessage(),e);
		BaseResp resp = new BaseResp();
		resp.setCode(ResponseCode.SERVERERR);
		resp.setMessage(e.getMessage());
        return resp;
    }


}
